﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CopySniffer.Common
{
    public static class Guard
    {
        public static void IsNotNull(object parameterValue, string parameterName)
        {
            if (parameterValue == null)
            {
                throw new ArgumentNullException(parameterName);
            }
        }

        public static void IsNotNullOrEmpty(string parameterValue, string parameterName)
        {
            if (parameterValue == null)
            {
                throw new ArgumentNullException(parameterName);
            }
            else if (parameterValue == String.Empty)
            {
                throw new ArgumentException(String.Format("Parameter {0} cannot be empty.", parameterName));
            }
        }

        public static void IsAssignableFrom(Type baseType, Type inheritedType, string parameterName)
        {
            if (!baseType.IsAssignableFrom(inheritedType))
            {
                throw new ArgumentException(String.Format("Parameter {0} is of type {1} which is not a subclass of {2}.",
                    parameterName, inheritedType, baseType));
            }
        }
    }
}
